import Toolbar from "@/components/ViewComponents/Toolbar";
import { useTranslation } from "react-i18next";
import { BasicTable, useTable, BasicColumn, FormSchema } from "@/components/Table";
import { treatmentPhmPage } from "@/api/MedicalExamination";
import moment from "moment";
import { message } from "antd";
import print from "@/utils/print/index";
export default function print_prescription() {
	const { t } = useTranslation();
	const formSchemaTop: FormSchema[] = [
		{
			label: t("felix_ui.dt_date"),
			field: "dt_date",
			component: "RangePicker",
			componentProps: {
				showTime: {
					defaultValue: [moment("00:00:00", "DD-MM-YYYY"), moment("23:59:59", "DD-MM-YYYY")]
				}
			}
		},
		{
			label: t("felix_ui.cli_name"),
			field: "clinicName",
			component: "Select"
		},
		{
			label: t("felix_ui.grp_subject"),
			field: "Object",
			component: "Select"
		}
	];
	const columns: BasicColumn[] = [
		{
			title: t("flandre_ui.drug_id"),
			dataIndex: "drugId"
		},
		{
			title: t("felix_ui.drugName"),
			dataIndex: "drugName"
		},
		{
			title: t("flandre_ui.active_ingredient"),
			dataIndex: "activeIngre"
		},
		{
			title: t("flandre_ui.unit_name"),
			dataIndex: "unitName"
		},
		{
			title: t("felix_ui.dt_date"),
			dataIndex: "timesPerDay"
		},
		{
			title: t("felix_ui.dosePerTime"),
			dataIndex: "dosePerTime"
		},
		{
			title: t("felix_ui.drugTakenMode"),
			dataIndex: "drugTakenMode"
		},
		{
			title: t("felix_ui.quantity"),
			dataIndex: "count"
		},
		{
			title: t("felix_ui.amount"),
			dataIndex: "salePrice"
		}
	];

	const [formTop, { getSelectRowKeys }] = useTable({
		api: treatmentPhmPage,
		columns,
		formConfig: {
			labelWidth: 100,
			showActionButtonGroup: true,
			showAdvancedButton: false,
			schemas: formSchemaTop
		},
		useSearchForm: true,
		rowSelection: { type: "checkbox" },
		searchInfo: {
			patId: "0db6d702dbf79b09aad99ee0de8a18f0"
		}
	});

	/** Function */
	const handlerAction = (key: string) => {
		switch (key) {
			case "print":
				print();
				if (!getSelectRowKeys().length) {
					message.warning("Please select at least one record !");
					return;
				}
				message.success("Function is not open,please wait~");
				break;
		}
	};
	return (
		<div className="flex page">
			<div className="page-content block">
				<BasicTable register={formTop}></BasicTable>
			</div>
			<Toolbar btnList={["print"]} action={handlerAction} />
		</div>
	);
}
